package org.codefinger.dao.impl;

import java.util.HashMap;
import java.util.Map;

public class QueryParam {

	private int[]				orders;

	private Map<String, Object>	namedParams;

	private Object[]			indexParams;

	private int					pageIndex;

	private int					pageSize;

	private boolean				isPaging;

	public QueryParam() {

	}

	public QueryParam(Object[] indexParams) {
		super();
		this.indexParams = indexParams;
	}

	public QueryParam(Map<String, Object> namedParams) {
		super();
		this.namedParams = namedParams;
	}

	public void setOrders(int... orders) {
		this.orders = orders;
	}

	public void setNamedParam(String name, Object object) {
		if (namedParams == null) {
			namedParams = new HashMap<String, Object>();
		}
		namedParams.put(name, object);
	}

	public void setNamedParams(Map<String, Object> params) {
		if (namedParams == null) {
			namedParams = new HashMap<String, Object>();
		}
		namedParams.putAll(params);
	}

	public void setIndexParam(Object[] iParams) {
		this.indexParams = iParams;
	}

	public void setPage(int pageIndex, int pageSize) {
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		isPaging = true;
	}

	public int[] getOrders() {
		return orders;
	}

	public Object getParam(String name) {
		return namedParams == null ? null : namedParams.get(name);
	}

	public Object getParam(int index) {
		Object[] indexParams = this.indexParams;
		return indexParams == null ? null : (index < indexParams.length ? indexParams[index] : null);
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public int getPageSize() {
		return pageSize;
	}

	public boolean isPaging() {
		return isPaging;
	}

}
